package cn.com.dcsgo.controller;

import cn.com.dcsgo.domain.MemberAddr;
import cn.com.dcsgo.dto.MemberAddressDTO;
import cn.com.dcsgo.service.MemberAddrService;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 收货地址RPC相关接口
 *
 * @author Dcsgo
 * @since 2025/11/17 9:54
 */
@Tag(name = "收货地址RPC相关接口")
@RestController
@RequestMapping("rpc/member/address")
public class AddressRPCController {
    @Resource
    private MemberAddrService memberAddrService;

    @GetMapping("default/openid/{openid}")
    @Operation(summary = "获取会员默认收货地址")
    public MemberAddressDTO getMemberDefaultAddress(@PathVariable("openid") String openid) {
        MemberAddr memberAddr = memberAddrService.getOne(
                new LambdaQueryWrapper<MemberAddr>()
                        .eq(MemberAddr::getOpenId, openid)
                        .eq(MemberAddr::getCommonAddr, 1)
                        .eq(MemberAddr::getStatus, 1)
        );
        MemberAddressDTO memberAddressDTO = new MemberAddressDTO();
        BeanUtil.copyProperties(memberAddr, memberAddressDTO);
        return memberAddressDTO;
    }
}
